package chabernac.gravidroid.model;

import junit.framework.TestCase;

public class LineTest extends TestCase {
    public void testLine() {
        Line theLine = new Line( new Vector( 0, 0 ), new Vector( 1, 1 ) );
        assertEquals( 0F, theLine.distanceToPoint( new Vector( 4, 4 ) ) );

        theLine = new Line( new Vector( 0, 0 ), new Vector( 2, 1 ) );
        assertEquals( 0F, theLine.distanceToPoint( new Vector( 2, 1 ) ) );

        theLine = new Line( new Vector( 1, 0 ), new Vector( 3, 1 ) );
        assertTrue( theLine.distanceToPoint( new Vector( 3, 1 ) ) < 0.00001 );
        assertTrue( theLine.distanceToPoint( new Vector( 1, 0 ) ) < 0.00001 );
    }

    public void testIntersectTwoLines2() {
        Line theL1 = Line.constructFromTwoPoints( new Vector( -1, -1 ), new Vector( 1, 1 ) );
        Line theL2 = Line.constructFromTwoPoints( new Vector( -1, 1 ), new Vector( 1, -1 ) );

        assertEquals( new Vector( 0, 0 ), theL1.intersect( theL2 ) );
        assertEquals( new Vector( 0, 0 ), theL2.intersect( theL1 ) );
    }

    public void testIntersectTwoLines() {
        Line theL1 = Line.constructFromTwoPoints( new Vector( -1, 0 ), new Vector( 1, 0 ) );
        Line theL2 = Line.constructFromTwoPoints( new Vector( 0, -1 ), new Vector( 0, 1 ) );

        assertEquals( new Vector( 0, 0 ), theL1.intersect( theL2 ) );
        assertEquals( new Vector( 0, 0 ), theL2.intersect( theL1 ) );
    }

    public void testIntersectTwoLines3() {
        Line theL1 = Line.constructFromTwoPoints( new Vector( -1, 0 ), new Vector( 1, 0 ) );
        Line theL2 = Line.constructFromTwoPoints( new Vector( 1, -1 ), new Vector( 1, 1 ) );

        assertEquals( new Vector( 1, 0 ), theL1.intersect( theL2 ) );
        assertEquals( new Vector( 1, 0 ), theL2.intersect( theL1 ) );
    }
}
